/**
 * class qui parse le fichier XML : Projet Android 
 * @author Floriance BRIN, Julie ESCOFFIER, Yoann GOBERT, Ikram NACIRI, Yann NIVET
 * @version 1.0
 * @date mars 2011
 * **/

package fr.imac.ProjetAndroid.citySearch;

import java.util.Vector;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class CityListParser extends DefaultHandler {
	private Boolean currentElement = false;
	private String currentValue = null;
	private Vector<String> namesList = new Vector<String>();
	private Vector<String> countriesList = new Vector<String>();
	private Vector<String> codesList = new Vector<String>();
	private Vector<Boolean> isZipCodeList = new Vector<Boolean>();
	
	
	@Override
	public void startElement(String uri, String localName, String qName, Attributes attributes) 
	throws SAXException {
		currentElement = true;
		
		if (localName.equals("location")){	
			namesList.add(attributes.getValue("cityname"));
			if(attributes.getValue("citytype").equals("1")){
				//pays autre que les USA
				countriesList.add(attributes.getValue("countryname"));
				codesList.add(attributes.getValue("citycode"));
				isZipCodeList.add(false);
			}else{
				countriesList.add(attributes.getValue("countryname")+" ("+attributes.getValue("statename")+")");
				codesList.add(attributes.getValue("zipcode"));
				isZipCodeList.add(true);
			}
		}
	}

	@Override
	public void endElement(String uri, String localName, String qName)
	throws SAXException {
		currentElement = false;
	}

	@Override
	public void characters(char[] ch, int start, int length)
	throws SAXException {
		if (currentElement) {
			setCurrentValue(new String(ch, start, length));
			currentElement = false;
		}
	}

	public void setNamesList(Vector<String> namesList) {
		this.namesList = namesList;
	}

	public Vector<String> getNamesList() {
		return namesList;
	}

	public void setCountriesList(Vector<String> countriesList) {
		this.countriesList = countriesList;
	}

	public Vector<String> getCountriesList() {
		return countriesList;
	}

	public void setCodesList(Vector<String> codesList) {
		this.codesList = codesList;
	}

	public Vector<String> getCodesList() {
		return codesList;
	}

	public void setIsZipCodeList(Vector<Boolean> isZipCodeList) {
		this.isZipCodeList = isZipCodeList;
	}

	public Vector<Boolean> getIsZipCodeList() {
		return isZipCodeList;
	}

	/**
	 * @param currentValue the currentValue to set
	 */
	public void setCurrentValue(String currentValue) {
		this.currentValue = currentValue;
	}

	/**
	 * @return the currentValue
	 */
	public String getCurrentValue() {
		return currentValue;
	}
}
